package com.fengye.rabbit.login.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fengye.rabbit.login.domain.User;
import com.fengye.rabbit.login.dto.UserLoginDTO;
import com.fengye.rabbit.login.mapper.UserMapper;
import com.fengye.rabbit.login.message.LoginPublisher;
import com.fengye.rabbit.login.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {

    @Resource
    UserMapper userMapper;

    @Autowired
    LoginPublisher loginPublisher;

    @Override
    public boolean login(UserLoginDTO dto) {
        log.info("UserServiceImpl: dto={}", dto);
        User user = userMapper.selectByUserNameAndPassword(dto.getUsername(), dto.getPassword());

        if (user != null) {
            dto.setUserId(user.getId());
            loginPublisher.sendLogMsg(dto);
            return true;
        }
        return false;
    }
}




